<template>
  <div class="app-container">
    <el-form :inline="true" ref="ruleForm" :model="formInline" class="demo-form-inline">
      <el-form-item label="">
        <el-col :span="6">
          <el-form-item prop="dateType">
            <el-select v-model="formInline.dateType" placeholder="请选择时间范围">
              <!--1提现时间，2出款时间，3风控审核时间-->
              <el-option label="提现时间" :value="1"></el-option>
              <el-option label="风险处理时间" :value="2"></el-option>
              <!--<el-option label="风控审核时间" :value="3"></el-option>-->
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item prop="time">
            <el-date-picker
              v-model="formInline.time"
              type="datetimerange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              :default-time="['00:00:00', '23:59:59']"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              :picker-options="pickerDayStep">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="提现金额">
        <el-col :span="11">
          <el-form-item prop="minAmount">
            <el-input  @keyup.enter.native="$emit('on-filter',formInline)" v-model="formInline.minAmount" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-form-item prop="maxAmount">
            <el-input  @keyup.enter.native="$emit('on-filter',formInline)" v-model="formInline.maxAmount" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item class="with-pre-select" label="用户提现银行" prop="cardNo">
        <el-input  @keyup.enter.native="$emit('on-filter',formInline)" placeholder="请输入卡号" v-model="formInline.cardNo" class="input-with-select">
          <el-select v-model="formInline.bankId" slot="prepend">
            <el-option
              v-for="item in bankList"
              :label="item.bankName"
              :key="item.bankId"
              :value="item.bankId"
            ></el-option>
          </el-select>
          <!--<el-button slot="append" icon="el-icon-search"></el-button>-->
        </el-input>
      </el-form-item>
      <el-form-item label="账户类型" prop="userType">
        <el-select v-model="formInline.userType" placeholder="请选择账户类型">
          <el-option
            v-for="item in consts.ACCOUNT_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"
            v-if="dataRoleCheck(dataPermissionAcountType[item.value])&&item.value!==-1"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="操作端" prop="clientType">
        <el-select v-model="formInline.clientType" placeholder="请选择操作端">
          <el-option
            v-for="item in consts.PAYMENT_PLATFORM"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="formInline.status" placeholder="请选择状态">
          <el-option
            v-for="item in consts.WITHDRAW_EXCEPTION_STATUS"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="风险类型" prop="riskType">
        <el-select v-model="formInline.riskType" :collapse-tags="true" multiple placeholder="请选择风险类型" v-if="formInline.userType===0">
          <el-option
            v-for="item in consts.RISK_TYPES"
            :label="item.title"
            :key="item.value"
            :value="item.value"
            v-if="dataRoleCheck(dataPermissionMemRiskType[item.value])"
          ></el-option>
        </el-select>

        <el-select v-model="formInline.riskType" :collapse-tags="true" multiple placeholder="请选择风险类型" v-if="formInline.userType===1">
          <el-option
            v-for="item in consts.RISK_TYPES"
            :label="item.title"
            :key="item.value"
            :value="item.value"
            v-if="dataRoleCheck(dataPermissionAgenRiskType[item.value])"
          ></el-option>
        </el-select>
        <!--<el-select v-if="formInline.userType!==0&&formInline.userType!==1">-->
          <!--<el-option></el-option>-->
        <!--</el-select>-->
        <!--<el-select v-model="formInline.riskType" :collapse-tags="true" multiple placeholder="请选择风险类型" v-if="formInline.userType==undefined||formInline.userType===-1">-->
          <!--<el-option-->
            <!--v-for="item in consts.RISK_TYPES"-->
            <!--:label="item.title"-->
            <!--:key="item.value"-->
            <!--:value="item.value"-->
            <!--v-if="dataRoleCheck(dataPermissionMemRiskType[item.value])||dataRoleCheck(dataPermissionAgenRiskType[item.value])"-->
          <!--&gt;</el-option>-->
        <!--</el-select>-->
      </el-form-item>
      <el-form-item class="with-pre-select" prop="keywords">
        <el-input  @keyup.enter.native="$emit('on-filter',formInline)" placeholder="请输入关键词" v-model="formInline.keywords" class="input-with-select">
          <el-select v-model="formInline.searchType" slot="prepend" placeholder="查询范围">
            <el-option label="提现单号" value="1"></el-option>
            <el-option label="账号名" value="2"></el-option>
            <el-option label="风险处理人" value="3"></el-option>
          </el-select>
          <!--<el-button slot="append" icon="el-icon-search"></el-button>-->
        </el-input>
      </el-form-item>
      <!-- <el-form-item label="出款类型" prop="dealType">
        <el-select v-model="formInline.dealType" placeholder="请选择出款类型">
          <el-option
            :label="'全部'"
            :key="consts.ALL"
            :value="consts.ALL"
          ></el-option>
          <el-option
            v-for="item in consts.WITHDRAW_DEAL_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="">
        <el-checkbox-group v-model="formInline.splitType">
          <el-checkbox label="关联拆单搜索" name="splitType"></el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="拆单状态" prop="splitStatus">
        <el-select v-model="formInline.splitStatus" placeholder="请选择拆单状态">
          <el-option
            :label="'全部'"
            :key="consts.ALL"
            :value="-1"
          ></el-option>
          <el-option label="已拆单" :value="1"></el-option>
          <el-option label="未拆单" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <!--<el-form-item label="层级" prop="userLevel">-->
        <!--<el-select :collapse-tags="true" v-model="formInline.userLevel" multiple placeholder="请选择层级">-->
          <!--<el-option-->
            <!--v-for="item in levelList"-->
            <!--:label="item.name"-->
            <!--:key="item.levelId"-->
            <!--:value="item.levelId"-->
          <!--&gt;</el-option>-->
        <!--</el-select>-->
      <!--</el-form-item>-->
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="$emit('on-filter',formInline)">搜索
      </el-button>
      <el-button @click="selfResetForm('ruleForm')">重置</el-button>
    </el-form>
  </div>

</template>

<script>
import { getWithdrawBankList } from '@/services/api/withdraw';
import { getUserLevelList } from '@/services/api/userLevel';
import { form, pickerOption } from '@/build';

export default {
  name: 'exception-filter',
  mixins: [form, pickerOption],
  data() {
    const riskType = _.map(consts.RISK_TYPES, 'value');
    return {
      bankList: [],
      levelList: [],
      riskType,
      formInline: {
        time: [moment().format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')],
        dateType: 1,
        minAmount: undefined,
        maxAmount: undefined,
        cardNo: undefined,
        bankId: undefined,
        userType: undefined,
        clientType: undefined,
        status: -3,
        riskType: [], // riskType,
        keywords: undefined,
        searchType: undefined,
        splitType: undefined,
        splitStatus: -1,
        // userLevel: [],
      },
      dataPermissionAcountType: {
        0: 'memAbnormalWithdraw',
        1: 'agenAbnormalWithdraw',
      },
      dataPermissionMemRiskType: {
        // 0: 'memWithdrawNormal',
        1: 'memWithdrawFirstAmountBig',
        2: 'memWithdrawSingleAmountBig',
        3: 'memWithdrawOneDayAmountBig',
        4: 'memWithdrawFrequent',
        5: 'memWithdrawProfitAbnormal',
        6: 'memWithdrawSevenDayAmountBig',
        7: 'memWithdrawIpConflict',
        8: 'memWithdrawDeviceConflict',
      },
      dataPermissionAgenRiskType: {
        // 0: 'agenWithdrawNormal',
        1: 'agenWithdrawFirstAmountBig',
        2: 'agenWithdrawSingleAmountBig',
        3: 'agenWithdrawOneDayAmountBig',
        4: 'agenWithdrawFrequent',
        5: 'agenWithdrawProfitAbnormal',
        6: 'agenWithdrawSevenDayAmountBig',
        7: 'agenWithdrawIpConflict',
        8: 'agenWithdrawDeviceConflict',
      },
    };
  },
  methods: {
    initUserType(){
      if (this.dataRoleCheck('memAbnormalWithdraw')) {
        this.formInline.userType = 0;
      } else if (!this.dataRoleCheck('memAbnormalWithdraw') && this.dataRoleCheck('agenAbnormalWithdraw')) {
        this.formInline.userType = 1;
      }
    },
    selfResetForm(formName) {
      this.formInline.splitType = undefined;
      this.resetForm(formName);
      this.initUserType();
      this.$emit('on-filter', this.formInline);
    },
  },
  mounted() {
   this.initUserType();
    this.bindGet(getWithdrawBankList, 'bankList', {
      action: 'getGrid',
      sendingData: 'formInline',
    });
    this.bindGet(getUserLevelList, 'levelList', { });
    this.getAll();
  },
};
</script>

<style lang="scss" scoped>
  .with-pre-select {
    .el-input-group__prepend {
      .el-select {
        width: 120px;
      }
    }
  }

  .money-range {
    .el-input {
      width: 100px;
    }
  }

</style>
